import fs from 'fs'

console.log('转换耗时');
const time = new Date().getTime()
const distPath = './dist/index.html'//打包路径的index.html
let htmlText = fs.readFileSync(distPath, 'utf-8')
let resultText = ''
let htmlArr = htmlText.match(/.*\n/g) || []
htmlArr.forEach(str => {
  str = str.replace(/\s?nomodule\s?/g, ' ')
  str = str.replace(/\s?crossorigin\s?/g, ' ')
  str = str.replace(/data-src/g, 'src')
  if (!/type="module"/i.test(str)) resultText += str
})
fs.writeFileSync(distPath, resultText, 'utf-8')
console.log('转换耗时', new Date().getTime() - time);